import React from 'react';
import BizIcon from '@/components/BizIcon';
import { Tooltip } from 'antd';
import classnames from 'classnames';
import styles from './index.less';

export default function Icon({ title, button, disabled, type, size = 20, tooltipProps, onClick, ...rest }) {
    const icon = (
        <div className={classnames({ [styles.button]: button })} onClick={disabled ? () => {} : onClick}>
            <BizIcon
                type={type}
                style={{ fontSize: `${size}px`, lineHeight: `${size}px`, cursor: onClick ? 'pointer' : '' }}
                className={classnames({ [styles.disabled]: disabled, [styles.icon]: !button })}
                {...rest}
            />
        </div>
    );

    if (!title) {
        return icon;
    }

    return (
        <Tooltip title={title} getPopupContainer={trigger => trigger.parentElement} {...tooltipProps}>
            {icon}
        </Tooltip>
    );
}
